package com.forum.controller.admin;

import com.forum.entity.Message;
import com.forum.entity.Reply;
import com.forum.service.ReplyService;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import java.util.List;

/**
 * @author 田勇
 * @date 2021/4/1 21:57
 */
@Controller
@RequestMapping("/admin")
public class ReplyController {
    @Autowired
    ReplyService replyService;

    @GetMapping("/reply")
    public String all(@RequestParam(required = false,defaultValue = "1",value = "pagenum")int pagenum, Model model){
        PageHelper.startPage(pagenum, 5);
        List<Reply> messages=replyService.findAll();

        PageInfo<Reply> pageInfo = new PageInfo<>(messages);
        model.addAttribute("pageInfo",pageInfo);
        return "admin/reply";
    }
    @GetMapping("/replyAll/{id}/delete")
    public String del(@PathVariable Integer id , RedirectAttributes attributes){
        replyService.del(id);
        attributes.addFlashAttribute("msg", "删除成功");
        return "redirect:/admin/reply";
    }
}
